﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using MYNAMESPACE;

namespace final_project
{
    public partial class Account : Form
    {
        private connect_db con;
        public string nm6;
        public string passvalue
        {

            get
            {
                return nm6;
            }
            set
            {
                nm6 = value;
            }
        }

        public Account()
        {
            InitializeComponent();
        }

        private void Account_Load(object sender, EventArgs e)
        {
            
            ID.Text= nm6;
            
        }
        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
            User f1 = new User();
            f1.ShowDialog();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {
           
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            // Validating Start code

            if (this.ValidateChildren(ValidationConstraints.Enabled))
            {
                MessageBox.Show("All controls are valid!");
                //Logic to save...
            }
            else
            {
                MessageBox.Show("There are invalid controls on the form.");
                //Return user to form...
            }

            //Validating end code 
            
            user us = new user();
            us.setnational_id(Int32.Parse(ID.Text.Trim()));
            con = new connect_db();
            con.sqlquery("select * from userdata where id= (@namep) ");
            con.cmd.Parameters.Add("@namep", us.getnational_id());
            con.sqlnonex();
            int c = 0;
            foreach (DataRow dr in con.QueryEx().Rows)
            {

                listBox1.Items.Add("the id is " + dr[0].ToString());
                listBox1.Items.Add("the name is " + dr[1].ToString());
                listBox1.Items.Add("the pass is " + dr[2].ToString());
                listBox1.Items.Add("the adreess is " + dr[3].ToString());
                listBox1.Items.Add("the mail is " + dr[4].ToString());
                listBox1.Items.Add("the phone is " + dr[5].ToString());
                listBox1.Items.Add("the gender is " + dr[6].ToString());
                listBox1.Items.Add("the balance is " + dr[8].ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

           


            user us = new user();
            us.setnational_id(Int32.Parse(ID.Text.Trim()));
            con = new connect_db();
            con.sqlquery("select balance from userdata where id=(@namep)");
            con.cmd.Parameters.Add("@namep", us.getnational_id());
            foreach (DataRow dr in con.QueryEx().Rows)
            {

                Balance.Text = dr["balance"].ToString();
            }
            us.setbalance(double.Parse(Balance.Text.Trim()));
            this.Hide();
            Diposite D = new Diposite();
            D.passvalue = Balance.Text;
            D.passvalue1 = ID.Text;
            D.ShowDialog();
           
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();

            user us = new user();
            us.setnational_id(Int32.Parse(ID.Text.Trim()));
            con = new connect_db();
            con.sqlquery("select balance from userdata where id=(@namep)");
            con.cmd.Parameters.Add("@namep", us.getnational_id());
            foreach (DataRow dr in con.QueryEx().Rows)
            {

                Balance.Text = dr["balance"].ToString();
            }
            Withdrow W = new Withdrow();
            W.passvalue = Balance.Text;
            W.passvalue1 = ID.Text;
            W.ShowDialog();
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            user us = new user();
            us.setnational_id(Int32.Parse(ID.Text.Trim()));
            con = new connect_db();
            con.sqlquery("delete   from userdata where id=(@namep)");
            con.cmd.Parameters.Add("@namep", us.getnational_id());
            con.sqlnonex();
            MessageBox.Show("the Accoun is deleted");
            this.Hide();
            User f1 = new User();
            f1.ShowDialog();

        }

        private void button6_Click(object sender, EventArgs e)
        {
             user us = new user();
            us.setnational_id(Int32.Parse(ID.Text));
            this.Hide();
            Shffle_money f2 = new Shffle_money();
            f2.passvalue = ID.Text;
            f2.ShowDialog();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            user us = new user();
            us.setnational_id(Int32.Parse(ID.Text));
            this.Hide();
            Bay_Bills f2 = new Bay_Bills();
            f2.passvalue = ID.Text;
            f2.ShowDialog();
        }

        private void ID_Validating(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(ID.Text))
            {

                e.Cancel = true;
                ID.Focus();
                errorProvider1.SetError(ID, "ID Must Be Entered !");

            }

            else if (!Regex.IsMatch(ID.Text, @"^\d{4}$"))
            {
                e.Cancel = true;
                errorProvider1.SetError(ID, "Valid ID 4 Number");

            }



            else if (Regex.IsMatch(ID.Text, @"^\d{14}$"))
            {
                e.Cancel = false;
                errorProvider1.SetError(ID, "");

            }
            else { }
        }
       
    }
}
